﻿using System.Linq;
using System;
using QueueUtils.Models;
using QueueUtils;
using System.Threading.Channels;

namespace APIDemo.ServiceManager
{ 
    public static class ServiceExtension
    {
        public static void AddHandleMsgChannel(this IServiceCollection services, ConfigurationManager configuration)
        {
            services.AddHostedService<MsgService>();
            services.AddSingleton<Channel<MessageData>>(_ =>
            {
                return Channel.CreateBounded<MessageData>(new BoundedChannelOptions(10)
                {
                    SingleReader = true,
                    FullMode = BoundedChannelFullMode.Wait,
                    AllowSynchronousContinuations = false,
                });
            });
        } 

    }
}
